package com.NULL.phony;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract.PhoneLookup;

import com.NULL.phony.filter.MessageActivity;
import com.NULL.phony.filter.R;

public class Helper {
	public static void notify(Context context, String message) {
		Notification notification = new Notification(R.drawable.icon,
				context.getString(R.string.app_name),
				System.currentTimeMillis());
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		Intent notificationIntent = new Intent(Intent.ACTION_PICK_ACTIVITY,
				null, context, MessageActivity.class);

		PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
				notificationIntent, 0);
		notification.setLatestEventInfo(context,
				context.getString(R.string.app_name), message, contentIntent);

		NotificationManager mNotificationManager = (NotificationManager) context
				.getSystemService(Context.NOTIFICATION_SERVICE);
		mNotificationManager.notify(R.drawable.icon, notification);
	}

	public static boolean isInContact(Context ctx, String phoneNumber) {
		Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
				Uri.encode(phoneNumber));
		Cursor cursor = ctx.getContentResolver().query(lookupUri,
				new String[] { PhoneLookup._ID }, null, null, null);
		boolean found=cursor.moveToNext();
		cursor.close();
		return found;
	}
}
